package com.chuangke.file.runner;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;

import com.chuangke.file.model.FileDbank;
import com.chuangke.file.schedule.FileScheduleTask;
import com.chuangke.file.service.FileDbankService;

//@Component
//@Order(2)
public class FileCacheOrderRunner implements CommandLineRunner {
	
	private static final Logger logger = LoggerFactory.getLogger(FileCacheOrderRunner.class);
	
	@Autowired
	private FileDbankService fileDbankService;
	
	@Autowired
	private FileScheduleTask FileScheduleTask ;
	
    @Override
    public void run(String... args) {
    	logger.info("cache load starting");
    	
    	fileDbankService.initDbankUsedSpace();
    	List<FileDbank> dbankList = fileDbankService.listDbank() ;
    	dbankList = dbankList==null ? new ArrayList<>() : dbankList ;
    	dbankList.forEach(dbank->{
    		fileDbankService.loadDbankById(dbank.getId());
    		fileDbankService.loadDbankSpace(dbank.getId()) ;
    	});
    	logger.info("cache load started");
    	
    	FileScheduleTask.registDbank();
    }
}